﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataIntegrityChecker.Data
{
    class Proposition
    {
        private DataRow baseRow;
        private List<DataRow> equalRows;
        private List<DataRow> similarRows;
        private int columnToCorrect;
        private string proposedValue;

        public Proposition(DataRow baseRow, List<DataRow> equalRows, List<DataRow> similarRows, int columnToCorrect)
        {
            this.similarRows = similarRows;
            this.equalRows = equalRows;
            this.columnToCorrect = columnToCorrect;
            this.baseRow = baseRow;
            this.proposedValue = BaseRow.Values[columnToCorrect];
        }

        internal DataRow BaseRow
        {
            get { return baseRow; }
            set { baseRow = value; }
        }

        internal List<DataRow> SimilarRows
        {
            get { return similarRows; }
            set { similarRows = value; }
        }

        internal List<DataRow> EqualRows
        {
            get { return equalRows; }
            set { equalRows = value; }
        }
        internal int ColumnToCorrect
        {
            get { return columnToCorrect; }
            set { columnToCorrect = value; }
        }

        public string ProposedValue { 
            get{
                return proposedValue;
            }
            set{
                proposedValue = value;
                UpdateSimilarEqualRows();
            }
        }

        private void UpdateSimilarEqualRows(){
            List<DataRow> newEqualList = new List<DataRow>();
            List<DataRow> newSimilarList = new List<DataRow>();
            foreach(DataRow row in equalRows){
                if(row.Values[columnToCorrect].Equals(proposedValue)){
                    newEqualList.Add(row);
                } else newSimilarList.Add(row);
            }
            foreach (DataRow row in similarRows)
            {
                if(row.Values[columnToCorrect].Equals(proposedValue)){
                    newEqualList.Add(row);
                } else newSimilarList.Add(row);
            }
            equalRows = newEqualList;
            similarRows = newSimilarList;
        }
    }
}
